""" 
DS18B02 温度传感器 读取温度

接线:
    DS_DQ 单线连接到 GPIO13
"""

from machine import Pin
import time
import onewire
import ds18x20

DS_DQ_PIN = 13
ds18b20 = ds18x20.DS18X20(onewire.OneWire(Pin(DS_DQ_PIN)))


if __name__ == "__main__":
    # 扫描ds18b20设备
    roms = ds18b20.scan()
    print("Found DS devices: ", roms)
    while True:
        ds18b20.convert_temp()
        time.sleep(2)
        for rom in roms:
            temp = ds18b20.read_temp(rom)
            print("温度值: {}".format(temp))
